package reflect;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.util.Scanner;

public class ReflectDemo3 {
    public static void main(String[] args) throws ClassNotFoundException, InvocationTargetException, InstantiationException, IllegalAccessException, NoSuchMethodException {
        Scanner scnner = new Scanner(System.in);
        System.out.println("请输入类名");
        String className = scnner.nextLine();
        Class cls = Class.forName(className);


        Constructor  constructor1 = cls.getConstructor();
        Object obj1 = constructor1.newInstance();
        System.out.println(obj1);


        Constructor constructor2 = cls.getConstructor(String.class);
        Object obg2 = constructor2.newInstance("张三");


        Constructor constructor3 = cls.getConstructor(String.class,int.class);
        Object obj3 = constructor3.newInstance("李四",20);

    }
}
